<template>
  <div>

    <div style="width: 400px;height: 700px;background-color: rgba(0,0,0,0.45);margin:100px auto;text-align: center;border-radius: 10px">
      <p style="font-size: 28px;font-family: '楷体';padding-top: 20px">项目申请</p>
      <hr style="width: 90%;height: 0.01px"/>
      <div style="margin-top: 20px">
        <div style="margin-top: 40px">
          <div>
            报价：<el-input v-model="InputPrice" placeholder="请输入你的项目报价" style="width: 70%;margin-top: 30px"></el-input>
          </div>
          <div>
            用时： <el-input  type="date" v-model="userTime" placeholder="项目用时" style="width: 70%;margin-top: 30px"></el-input>
          </div>
          <div style="margin-top: 30px;width: 80%">
            选择小组：  <el-select v-model="value2" placeholder="请选择">
            <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled">
            </el-option>
          </el-select>
          </div>
        </div>
        <div style="width: 85%;margin-top: 50px">
          <form style="width: 100%">
            <p style="width: 100%;margin-left: 28px; text-align: left">请上传项目计划书</p>
            <input type="file" @change="getFilee($event)">
            <button class="button button-primary button-pill button-small" @click="submite($event)">提交</button>
          </form>
        </div>
        <div style="width: 100%">
          <el-button plain style="margin-top: 20px;width: 100px" size="small" @click="register()">发出申请</el-button>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        id:'',
        InputPrice:'',
        userTime:'',
        file: '',
        filee: '',
        options2: [{
          value: '',
          label: '',

        }
        ],
        value2: ''
      }
    },
    mounted: function(){

      var user= JSON.parse(window.sessionStorage.getItem("user"));
       let r=user.id

      axios.post('/workroom/findGroup',{
        id:r,
        wid:r
      }).then((response) => {

        if(response.data!==null){
          let ee=response.data
          var data=[];
          for(var c=0;c<ee.length;c++){
            var eee=ee[c]
            console.log(eee)
            var obj={}
           obj.value=eee.id
           obj.label=eee.groupname
            data[c]=obj
          }
          this.options2=data
          console.log(this.options)
        }  else{

        }
      }).catch((response)=>{

      })
    },
    methods: {

      getFile: function (evente) {
        this.file = event.target.files[0];
        console.log(this.file);
      },
      getFilee: function (event) {
        this.filee = event.target.files[0];
        console.log(this.filee);
      },
      submit: function (event) {
        //阻止元素发生默认的行为
        var _this=this
        event.preventDefault();
        let formData = new FormData();
        console.log(formData)
        formData.append("file", this.file)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            alert(response.data);
            console.log(response);
            var a= response.data;
            //var e=a.split("*");
            //console.log(e[1])
            _this.file=a;
            // window.location.reload();
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },
      submite: function (event) {
        var _this=this
        //阻止元素发生默认的行为
        event.preventDefault();
        let formData = new FormData();
        console.log(formData)
        formData.append("file", this.filee)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            alert(response.data);
            console.log(response);
            var a= response.data;
            //  var e=a.split("*");
            // console.log(e[1])
            _this.filee=a;
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },
      register(){

         console.log(this.filee)

          var user= JSON.parse(window.sessionStorage.getItem("user"));
          this.id=user.id
          var cc= this.$route.query.mallCode
          console.log(cc)
          axios.post('/workroom/insertProjectApply',{

            id:this.id,   //用户id
            idd: cc,  //项目id
            price:this.InputPrice,
            timeLimit:this. userTime,
            projectDoc:this.filee,
            style:this.value2

          }).then((response) => {
            // console.log(response.data.states)
            if(response.data.states==800){
              this.$notify({
                title: '成功',
                message: '申请成功',
                type: 'success',
                duration:2000
              });
              this.$router.push({
                path: '/Project',
                query: {

                  mallCode: cc

                }})


            }else{
              this.$notify.error({
                title: '错误',
                message: response.data.message,
                type: 'warning',
                duration:0
              });
            }
          }).catch((response)=>{

          })
        }

      },





  }
</script>

<style scoped>

</style>
